home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / CLI_Tools.lha / GetWord.c < prev    next >
C/C++ Source or Header  |  1995-02-03  |  2KB  |  117 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     MODULE
  5.     GetWord.c
  6.  
  7.     DESCRIPTION
  8.     Get a number and some strings on Commandline
  9.     and write one of them to StdOut
  10.  
  11.     NOTES
  12.     Kickstart 2.0+ required
  13.     compiles w/ Dice 2.07R - inline-pragmas required
  14.     compiles w/ SAS/C v6.51
  15.  
  16.     BUGS
  17.     none known
  18.  
  19.     TODO
  20.  
  21.     EXAMPLES
  22.     > getword 1 x y z
  23.     y
  24.  
  25.     SEE ALSO
  26.  
  27.     INDEX
  28.  
  29.     HISTORY
  30.     01-08-93 b_noll created
  31.  
  32.     AUTHOR
  33.     Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
  34.     b_noll@informatik.uni-kl.de
  35.  
  36. ******************************************************************************/
  37.  
  38. /**************************************
  39.         Includes
  40. **************************************/
  41.  
  42. #ifndef   EXEC_LIBRARIES_H
  43. # include <exec/libraries.h>
  44. #endif /* EXEC_LIBRARIES_H */
  45.  
  46. #ifndef   CLIB_EXEC_PROTOS_H
  47. # include <clib/exec_protos.h>
  48. #endif /* CLIB_EXEC_PROTOS_H */
  49.  
  50. #ifndef   DOS_DOS_H
  51. # include <dos/dos.h>
  52. #endif /* DOS_DOS_H */
  53.  
  54. #ifndef   CLIB_DOS_PROTOS_H
  55. # include <clib/dos_protos.h>
  56. #endif /* CLIB_DOS_PROTOS_H */
  57.  
  58. #include <proto/dos.h>
  59. #include <proto/exec.h>
  60.  
  61. /**************************************
  62.         Structures
  63. **************************************/
  64.  
  65. struct _arg {
  66.     LONG  * num;
  67.     STRPTR* words;
  68. }; /* struct  */
  69.  
  70. /**************************************
  71.         Global Variables
  72. **************************************/
  73.  
  74.  
  75. /**************************************
  76.         Implementation
  77. **************************************/
  78.  
  79. long _main (void)
  80. {
  81.     const char      * version = "$VER: GetWord 1.0 (23.8.93)";
  82.     long        retval  = 20;
  83.     struct Library* SysBase = *((struct Library**)4L);
  84.     struct Library* DOSBase;
  85.  
  86.     if (DOSBase = OpenLibrary (DOSNAME, 37)) {
  87.     struct _arg    argv    = { NULL, NULL };
  88.     APTR args;
  89.     retval     = 10;
  90.     if (args = (void*)ReadArgs( "NUMBER/N/A,WORDS/M", (LONG*)&argv, NULL)) {
  91.         long num;
  92.         long i;
  93.         num  = *(argv.num);
  94.         if (num < 0) {
  95.         for (i = 0; argv.words[i]; ++i);
  96.         num += i+1;
  97.         } /* if */
  98.         for (i = 0; (i < num) && argv.words[i]; ++i);
  99.         if ((i == num) && i) {
  100.         retval = 5;
  101.         if (PutStr (argv.words[i-1]) == 0) retval = 0;
  102.         } else {
  103.         retval = 9;
  104.         } /* if */
  105.         PutStr("\n");
  106.         FreeArgs (args);
  107.     } /* if */
  108.     CloseLibrary (DOSBase);
  109.     } /* if */
  110.     return (retval);
  111. } /* _main */
  112.  
  113. /******************************************************************************
  114. *****  END GetWord.c
  115. ******************************************************************************/
  116.  
  117.